<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8" />
    <title>注册</title>
    <link rel="stylesheet" type="text/css" href="css/public.css" />
    <link rel="stylesheet" type="text/css" href="css/login.css" />
</head>

<body>
    <!-------------------reg-------------------------->
    <div class="reg">
        <form action="#" method="post">
            <h1><a href="index.html"></a></h1>
            <p>用户注册</p>
            <p>
                <input type="text" id="user" name="" value="" placeholder="请输入邮箱" />
            </p>
            <p>
                <input type="text" id="password" name="" value="" placeholder="请输入密码" />
            </p>
            <p>
                <input type="text" id="password2" name="" value="" placeholder="请确认密码" />
            </p>
            <!-- <p class="txtL txt">
                <input class="code" type="text" name="" value="" placeholder="验证码" /><img src="img/temp/code.jpg" />
            </p> -->
            <p><input type="submit" name="" id="btn" value="注册" /></p>
            <p class="txtL txt">完成此注册，即表明您同意了我们的</p>
            <p class="txt">
                <a href="login.html"><span></span>已有账号登录</a>
            </p>
            <!--<a href="#" class="off"><img src="img/temp/off.png"></a>-->
        </form>
    </div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.9.1/jquery.js"></script>
<script>
    var baseUrl = "http://127.0.0.1";
    $("#btn").on("click", function () {
        var user = $("#user").val();
        var password = $("#password").val();
        var password2 = $("#password2").val();
        if (user == "" || password == "") {
            alert("用户或密码不能为空！")
            return;
        } else if (password2 != password) {
            alert("两次输入的密码不同！")
            return
        }
        $.post(`${baseUrl}/register`, { "tel": user, "password": password }, function (data) {
            if (data.result == 1) {
                alert("用户注册成功！");
                localStorage.id = data.user.id
                window.location.href = "/index.html";
            } else {
                alert("用户或密码错误！");
                return;
            }
        });
    });
</script>

</html>